/**
* @author: Lu
* @date: 2021.02.22
* @brief: 发送带外数据客户端
*/
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<assert.h>
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<errno.h>
#include<string.h>

int main(int argc,char* argv[])
{
	if(argc <= 2)
	{
		printf("usage: %s ip_address port_number\n",basename(argv[0]));
		return 1;
	}
	
	const char* ip = argv[1];
	int port = atoi(argv[2]);

	struct sockaddr_in serverAddr;
	bzero(&serverAddr,sizeof(serverAddr));
	serverAddr.sin_family = AF_INET;
	inet_pton(AF_INET,ip,&serverAddr.sin_addr);
	serverAddr.sin_port = htons(port);

	int sockfd = socket(AF_INET,SOCK_STREAM,0);
	assert(sockfd >=0);

	if(connect(sockfd,(struct sockaddr*)&serverAddr,sizeof(serverAddr)) <0)
	{
		printf("Connection Failed!\n");
	}
	else
	{
		const char* oob_data = "abc";
		const char* normal_data = "123";
		send(sockfd,normal_data,strlen(normal_data),0);
		send(sockfd,oob_data,strlen(oob_data),MSG_OOB);
		send(sockfd,normal_data,strlen(normal_data),0);
	}
}
